/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.anism.business;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.anism.entity.Employee;
import org.anism.entity.HolidayRequest;
import org.anism.entity.RequestHistory;

/**
 *
 * @author user
 */
public class Planning {

    private Employee employee;
    
    Collection<HolidayRequest> requestsToDisplay;

    public Collection<HolidayRequest> getRequestsToDisplay() {
        return requestsToDisplay;
    }
    
    private Planning(){
        
    }

    public Planning(Employee employee) {
        this.employee = employee;
        requestsToDisplay = new ArrayList<HolidayRequest>();
        Date now = GregorianCalendar.getInstance().getTime();

        Collection<HolidayRequest> holidayRequests = employee.getHolidayRequestCollection1();
        Logger.getLogger(Planning.class.getName()).log(Level.INFO, "Planning :: Employee : {0} => nb holidayRequests = {1}", new Object[]{employee.getEmployeeId(), holidayRequests.size()});

        for (HolidayRequest hReq : holidayRequests) {
            
            requestsToDisplay.add(hReq);

            Logger.getLogger(Planning.class.getName()).log(Level.INFO, "Planning :: holidayRequest : {0}", hReq.toString());
            
            // Check if holiday ends after today

//            if (hReq.getEndDate().after(now)) {
//
//                Collection<RequestHistory> history = hReq.getRequestHistoryCollection();
//
//                for (RequestHistory rHist : history) {
//
//                    // check if holiday is RH_validated or already validated
//                    if (rHist.getStatus().equals(IRequestStatus.REQUEST_STATUS_RH_VALIDATED)
//                            || rHist.getStatus().equals(IRequestStatus.REQUEST_STATUS_VALIDATED)) {
//                        // add holiday to display
//                        requestsToDisplay.add(hReq);
//                        break;
//                    }
//                }
//            }
        }
    }
}
